<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">

<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>直播间列表</title>

    <link href="../../resource/css/bootstrap.min.css?v=3.3.5" rel="stylesheet"
          th:href="@{/resource/css/bootstrap.min.css?v=3.3.5}"/>
    <link href="../../resource/hotui/css/font-awesome.min.css" th:href="@{/resource/hotui/css/font-awesome.min.css}"
          rel="stylesheet">
    <!-- Morris -->
    <link href="../../resource/hotui/css/plugins/morris/morris-0.4.3.min.css"
          th:href="@{/resource/hotui/css/plugins/morris/morris-0.4.3.min.css}" rel="stylesheet">
    <link href="../../resource/css/animate.min.css" rel="stylesheet" th:href="@{/resource/css/animate.min.css}"/>
    <link href="../../resource/hotui/css/style.min-1.0.8.css" th:href="@{/resource/hotui/css/style.min-1.0.8.css}"
          rel="stylesheet">
    <link href="../../resource/hotui/css/hotui.style.override.css"
          th:href="@{/resource/hotui/css/hotui.style.override.css}" rel="stylesheet"/>
    <link href="../../resource/hotui/js/plugins/datetimepick/css/daterangepicker.css"
          th:href="@{/resource/hotui/js/plugins/datetimepick/css/daterangepicker.css}" rel="stylesheet"/>

    <style type="text/css">
        .hr-line-dashed {
            margin: 10px 0;
            height: 1px;
            border-top: 1px dashed #e7eaec;
            background-color: #fff;
            color: #fff;
        }
    </style>
</head>

<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight tooltip-demo">
    <!--search-->
    <form role="form" id="searchForm" class="search-panel" method="get"
          th:object="${condition}">
        <div class="row">
            <div class="col-lg-12">
                <div class="ibox">
                    <div class="ibox-content">
                        <div class="form-inline">
                            <input type="hidden" th:value="${pageIndex}" name="pageIndex"/>
                            <input type="hidden" th:value="*{auditStatus}" name="auditStatus"/>
                            <div class="form-group m-r-sm">
                                <label class=" control-label" for="merchantKey">商家：</label>
                                <input type="text" class="form-control input-sm mb10" id="merchantKey"
                                       th:value="*{merchantKey}"
                                       name="merchantKey" placeholder="姓名/手机" style="width: 156px;"/>
                            </div>
                            <div class="form-group m-r-sm">
                                <label class=" control-label" for="title">直播间名称：</label>
                                <input type="text" class="form-control input-sm mb10" id="title"
                                       th:value="*{title}"
                                       name="title" placeholder="直播间名称" style="width: 156px;"/>
                            </div>
                            <div class="form-group m-r-sm">
                                <button type="button" onclick="listHandler.search(1)"
                                        class="btn btn-primary btn-sm m-b-none searchBtn">筛选
                                </button>
                                <button type="button" onclick="listHandler.searchAll()"
                                        class="btn btn-primary btn-sm m-b-none">显示全部
                                </button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </form>
    <!--search-->
    <div class="row">
        <div class="col-lg-12">
            <div class="ibox float-e-margins m-b-none">
                <div class="tabs-container">
                    <ul class="nav nav-tabs">
                        <li th:class="${condition.auditStatus==1?'active':''}" class="active">
                            <a th:href="@{/live/list(auditStatus=1)}" href="#">已审核</a>
                        </li>
                        <li th:class="${condition.auditStatus==0?'active':''}">
                            <a th:href="@{/live/list(auditStatus=0)}" href="#">待审核</a>
                        </li>
                        <li th:class="${condition.auditStatus==2?'active':''}">
                            <a th:href="@{/live/list(auditStatus=2)}" href="#">审核失败</a>
                        </li>
                    </ul>
                    <div class="tab-content">
                        <div class="tab-pane active">
                            <div class="panel-body table-responsive">
                                <table class="table table-bordered table-hover table-center">
                                    <thead>
                                    <tr>
                                        <th>直播间ID</th>
                                        <th>直播间封面</th>
                                        <th>房间名称</th>
                                        <th>抽成比例</th>
                                        <th>店铺</th>
                                        <th>主营类目</th>
                                        <th>开通时间</th>
                                        <th>直播状态</th>
                                        <th>房间状态</th>

                                        <th>排序</th>
                                        <th>操作</th>
                                    </tr>
                                    </thead>
                                    <tbody>

                                    <tr th:each="room:${rooms}">
                                        <td th:text="${room.id}"></td>
                                        <td>
                                            <img th:src="${@resourceService.get(room.data.logo).getURI()}"
                                                 style="width: 50px;height: 50px;border-radius: 10px"
                                                 src="../../resource/img/p1.jpg">
                                            <input type="hidden" th:id="${'img1'+room.id}"
                                                   th:value="${@resourceService.get(room.data.logo).getURI()}"/>
                                            <input type="hidden" th:id="${'img2'+room.id}"
                                                   th:value="${@resourceService.get(room.data.landscapeCover).getURI()}"/>
                                            <input type="hidden" th:id="${'img3'+room.id}"
                                                   th:value="${@resourceService.get(room.data.portraitCover).getURI()}"/>
                                            <input type="hidden" th:id="${'title'+room.id}"
                                                   th:value="${room.data.title}"/>
                                            <input type="hidden" th:id="${'desc'+room.id}"
                                                   th:value="${room.data.description}"/>
                                            <input type="hidden" th:id="${'title'+room.id}"
                                                   th:value="${room.data.title}"/>
                                            <input type="hidden" th:id="${'merchant'+room.id}"
                                                   th:value="${room.merchant.data.title}"/>
                                            <input th:id="${'cate'+room.id}"
                                                   th:if="${room.merchant.data.mainCategory!=null}" type="hidden"
                                                   th:value="${room.merchant.data.mainCategory.catName}"/>
                                        </td>
                                        <td th:text="${room.data.title}">剑南的房间</td>
                                        <td th:text="${room.rewardRate}">0.3</td>
                                        <td th:text="${room.merchant.data.title}">剑南的淘宝店</td>
                                        <td th:if="${room.merchant.data.mainCategory!=null}"
                                            th:text="${room.merchant.data.mainCategory.catName}">翡翠
                                        </td>
                                        <td th:text="${#temporals.format((room.openTime!=null?room.openTime:room.createTime),'yyyy-MM-dd HH:mm:ss')}">
                                            2019-12-12 12:12:12
                                        </td>
                                        <td>
                                            <span th:class="${room.isPlaying()?'color-primary':'color-warning'}"
                                                  th:text="${room.isPlaying()?'直播中':'未开播'}">未开播</span>
                                            <br>
                                            <span th:if="${room.isEnableRobot()}">已开启机器人</span>
                                        </td>
                                        <td>
                                            <span class="color-primary"
                                                  th:class="${room.enabled?'color-primary':'color-danger'}"
                                                  th:text="${room.enabled?'激活':'冻结'}">激活</span>
                                            <br>
                                            <span class="color-primary" th:text="${room.platform?'平台':'私域'}"></span>
                                            <span class="color-danger" th:if="${!room.platform}"
                                                  th:text="${room.recommendFlag?'/推荐':''}"></span>
                                        </td>
                                        <td th:text="${room.orderWeight}">0</td>
                                        <td>
                                            <th:block th:if="${room.auditStatus.code==0}">
                                                |
                                                <a th:href="|javascript:listHandler.showModal(${room.id})|"
                                                   href="javascript:listHandler.showModal(1)">审核</a>
                                            </th:block>
                                            <th:block th:if="${room.auditStatus.code==1}">
                                                <th:block th:if="${room.isPlaying()}">
                                                    <a href="javascript:listHandler.setRobotConfig(1)"
                                                       th:href="|javascript:listHandler.setRobotConfig(${room.id})|"
                                                       th:if="${!room.isEnableRobot()}">开启机器人</a>
                                                    <a href="javascript:listHandler.enableRobot(1)"
                                                       th:href="|javascript:listHandler.enableRobot(${room.id},false)|"
                                                       th:if="${room.isEnableRobot()}">关闭机器人</a>
                                                    |
                                                </th:block>
                                                <th:block th:if="${!room.platform}">
                                                    <a href="javascript:listHandler.rec(1)"
                                                       th:href="|javascript:listHandler.rec(${room.id})|">推荐</a>
                                                    |
                                                </th:block>
                                                <a href="javascript:listHandler.modifyPlatformType(1,false)"
                                                   th:href="|javascript:listHandler.modifyPlatformType(${room.id},false)|"
                                                   th:if="${room.platform}">设为私域</a>
                                                <a href="javascript:listHandler.modifyPlatformType(1,true)"
                                                   th:href="|javascript:listHandler.modifyPlatformType(${room.id},true)|"
                                                   th:if="${!room.platform}">设为平台</a>
                                                <br/>
                                                <a th:href="|javascript:listHandler.sort(${room.id},${room.orderWeight})|"
                                                   href="javascript:listHandler.sort(1,1)">排序</a>
                                                |
                                                <a th:if="${room.enabled}"
                                                   th:href="|javascript:listHandler.enableToggle(${room.id},false)|"
                                                   href="javascript:listHandler.enableToggle(1,false)">冻结</a>
                                                <a th:if="${!room.enabled}"
                                                   th:href="|javascript:listHandler.enableToggle(${room.id},true)|"
                                                   href="javascript:listHandler.enableToggle(1,true)">激活</a>
                                                <br/>
                                                <a th:href="|javascript:listHandler.detail(${room.id},'${room.data.title}')|"
                                                   href="javascript:listHandler.detail(1,'')">查看详情</a>
                                                |
                                                <a th:href="|javascript:listHandler.setRate(${room.id},${room.rewardRate})|"
                                                   href="javascript:listHandler.rateSet(1,1)">抽成比例</a>

                                                <th:block th:if="${room.isPlaying()}">|
                                                    <a href="javascript:listHandler.modifyMemberNum(1,1)"
                                                       th:href="|javascript:listHandler.modifyMemberNum(${room.id})|">设置观看人数</a>
                                                </th:block>
                                                <br/>
                                                <a href="javascript:listHandler.showReplyMessageModal(1,1)"
                                                   th:href="|javascript:listHandler.showReplyMessageModal(${room.id})|">回复消息</a>

                                            </th:block>
                                        </td>
                                    </tr>
                                    </tbody>
                                </table>
                                <p style="float: left; margin: 20px 0;">
                                    共<span th:text="${totalRecords}"></span>条记录，当前第<span th:text="${pageIndex}"></span>/<span
                                        th:text="${totalPages==0?1:totalPages}"></span>，每页20条记录
                                </p>
                                <ul style="float: right;" class="pagination pagination-split">
                                </ul>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<script type="text/html" id="audit_template">
    <input type="hidden" id="audit_roomId"/>
    <div class="form-horizontal" style="width: 600px;">
        <div class="form-group ">
            <label class="col-sm-2 control-label">直播间名称:</label>

            <div class="col-sm-10">
                <input id="audit_title" type="text" class="form-control input-sm" readonly
                       placeholder="直播间名称"/>
            </div>
        </div>
        <div class="hr-line-dashed "></div>
        <div class="form-group ">
            <label class="col-sm-2 control-label">直播间描述:</label>

            <div class="col-sm-10">
                <input type="text" id="audit_description" readonly
                       class="form-control input-sm" placeholder="直播间描述"/>
            </div>
        </div>
        <div class="hr-line-dashed "></div>
        <div class="form-group ">
            <label class="col-sm-2 control-label">所属店铺:</label>

            <div class="col-sm-10">
                <input type="text" id="audit_merchant" readonly
                       class="form-control input-sm" placeholder="所属店铺"/>
            </div>
        </div>
        <div class="hr-line-dashed "></div>
        <div class="form-group ">
            <label class="col-sm-2 control-label">主营类目:</label>

            <div class="col-sm-10">
                <input type="text" id="audit_cate" readonly
                       class="form-control input-sm" placeholder="主营类目"/>
            </div>
        </div>
        <div class="hr-line-dashed "></div>
        <div class="form-group ">
            <label class="col-sm-2 control-label">正方形封面:</label>

            <div class="col-sm-10">
                <img id="audit_img1" class="squareView" style="height: 70px;" src="../../resource/img/p1.jpg"/>
            </div>
        </div>
        <div class="hr-line-dashed "></div>
        <div class="form-group ">
            <label class="col-sm-2 control-label">横向封面:</label>

            <div class="col-sm-10">
                <img id="audit_img2" class="horizontalView" style="height: 70px;" src="../../resource/img/p1.jpg"/>
            </div>
        </div>
        <div class="hr-line-dashed "></div>
        <div class="form-group ">
            <label class="col-sm-2 control-label">纵向封面:</label>

            <div class="col-sm-10">
                <img id="audit_img3" class="portraitView" style="height: 70px;" src="../../resource/img/p1.jpg"/>
            </div>
        </div>
        <div class="hr-line-dashed "></div>
        <div class="form-group">
            <div style="text-align: center">
                <button class="btn btn-success btn-submit" type="button" onclick="listHandler.audit(true)">
                    审核通过
                </button>
                <button class="btn btn-danger btn-submit" type="button" onclick="listHandler.audit(false)">
                    拒绝申请
                </button>
            </div>
        </div>
    </div>
</script>


<div class="modal-content-tag" id="robot_config_template">
    <form id="robot_form">
        <input name="robot_room_id" type="hidden"/>
        <div class="form-horizontal" style="width: 479px;">
            <div class="form-group form-inline">
                <label class="col-sm-3 control-label">频率(秒)：</label>
                <div class="col-sm-9">
                    <input class="form-control input-sm only-num" id="robot_min" name="robot_min" placeholder="最小频率"
                           required style="width: 80px" type="text"/>
                    <input class="form-control input-sm only-num" id="robot_max" name="robot_max" placeholder="最大频率"
                           required style="width: 80px" type="text"/>
                </div>
            </div>
        </div>
    </form>
</div>

<!--基础框架js-->
<script src="../../resource/js/jquery.min.js?v=2.1.4" th:src="@{/resource/js/jquery.min.js?v=2.1.4}"></script>
<script src="../../resource/js/bootstrap.min.js?v=3.3.5" th:src="@{/resource/js/bootstrap.min.js?v=3.3.5}"></script>
<script src="../../resource/hotui/js/hot/bootstrap.hot.extra-utils.js"
        th:src="@{/resource/hotui/js/hot/bootstrap.hot.extra-utils.js(123123)}"></script>
<script src="../../resource/hotui/js/hot/bootstrap.hot.extra-init.js"
        th:src="@{/resource/hotui/js/hot/bootstrap.hot.extra-init.js}"></script>
<script src="../../resource/hotui/js/content.min.js" th:src="@{/resource/hotui/js/content.min.js}"></script>
<script src="../../resource/lib/moment.min.js" th:src="@{/resource/lib/moment.min.js}"></script>
<script src="../../resource/hotui/js/plugins/datetimepick/js/daterangepicker.js"
        th:src="@{/resource/hotui/js/plugins/datetimepick/js/daterangepicker.js}"></script>


<script src="../resource/lib/jquery-validation/dist/jquery.validate.min.js"></script>
<script src="../resource/lib/jquery-validation/dist/messages_cn.js"></script>
<script src="../../resource/hotui/js/hot/bootstrap.hot.extra-validate.js"
        th:src="@{/resource/hotui/js/hot/bootstrap.hot.extra-validate.js}"></script>


<script type="text/javascript" th:inline="javascript">
    const pageIndex = /*[[${pageIndex}]]*/  1;
    const totalPages = /*[[${totalPages}]]*/  0;
    const pageUri = /*[[@{/live/list}]]*/  "";
    const ajaxUri = /*[[@{/live}]]*/  "";
    const sendMessageUri = /*[[@{/live/sendGeneralMessage}]]*/  "";
    const sendTemplateMessage = /*[[@{/live/sendTemplateMessage}]]*/  "";
</script>
<script>


    let robotConfigModal = $('#robot_config_template').modal('开启机器人配置', function () {
        $('#robot_form').submit();
    });


    var auditModal = $("#audit_template").modal("直播间审核", function () {

    }, {
        btn: []
    });
    $(function () {
        //初始化分页
        var pageinate = new hot.paging(".pagination", pageIndex, totalPages, 7);

        pageinate.init(function (p) {
            listHandler.search(p);
        });
        $(document).keyup(function (event) {
            if (event.keyCode === 13) {
                $(".searchBtn").trigger("click");
            }
        });
    });

    var listHandler = {
        search: function (pageIndex) {
            $("input[name=pageIndex]").val(pageIndex);
            $("#searchForm").submit();
        },
        searchAll: function () {
            window.location.href = pageUri;
        },
        detail: function (roomId, title) {
            let detailUri = ajaxUri + "/detail/products?roomId=" + roomId;
            hot.newTab(detailUri, title)
        },
        stop: function (roomId) {
            hot.confirm("确定关闭该直播？所有直播中的场次将被关闭", function () {
                hot.ajax(ajaxUri + "/stop/" + roomId, null, function (apiResult) {
                    if (apiResult.resultCode === 2000) {
                        hot.tip.success("操作成功", function () {
                            window.location.reload();
                        });
                    } else {
                        hot.tip.error("操作失败--" + apiResult.resultMsg);
                    }
                }, function () {
                }, "post", 300);
            });
        },
        enableToggle: function (roomId, enable) {
            hot.confirm("确定冻结该直播间？", function () {
                hot.ajax(ajaxUri + "/enableToggle/" + roomId, {
                    enable: enable
                }, function (apiResult) {
                    if (apiResult.resultCode === 2000) {
                        hot.tip.success("操作成功", function () {
                            window.location.reload();
                        });
                    } else {
                        hot.tip.error("操作失败--" + apiResult.resultMsg);
                    }
                }, function () {
                }, "post", 300);
            })
        },
        rateSet: function (roomId, rate) {
            layer.prompt({title: '设置抽成比例', formType: 0, value: rate}, function (text, index) {
                if (text.length === 0) {
                    hot.tip.msg("请输入抽成比例");
                }
                hot.ajax(ajaxUri + "/setRewardRate/" + roomId, {
                    rate: text
                }, function (apiResult) {
                    if (apiResult.resultCode === 2000) {
                        hot.tip.success("操作成功", function () {
                            window.location.reload();
                        });
                    } else {
                        hot.tip.error("操作失败--" + apiResult.resultMsg);
                    }
                }, function () {
                }, "post", 300);
            });
        },
        showModal: function (roomId) {
            auditModal.show(function () {
                $("#audit_roomId").val(roomId);
                $("#audit_title").val($("#title" + roomId).val());
                $("#audit_description").val($("#desc" + roomId).val());
                $("#audit_img1").attr("src", $("#img1" + roomId).val());
                $("#audit_img2").attr("src", $("#img2" + roomId).val());
                $("#audit_img3").attr("src", $("#img3" + roomId).val());
                $("#audit_merchant").val($("#merchant" + roomId).val());
                $("#audit_cate").val($("#cate" + roomId).val());
            })
        },
        audit: function (result) {
            let roomId = $("#audit_roomId").val();
            if (result) {
                hot.confirm("确定通过申请？", function () {
                    hot.ajax(ajaxUri + "/audit/" + roomId, {
                        auditStatus: 1
                    }, function (apiResult) {
                        if (apiResult.resultCode === 2000) {
                            hot.tip.success("操作成功", function () {
                                window.location.reload();
                            })
                        } else {
                            hot.tip.error("操作失败-" + apiResult.resultMsg);
                        }
                    }, function () {
                    }, "post", 300);
                })
            } else {
                layer.prompt({title: '拒绝理由', formType: 2}, function (text, index) {
                    hot.ajax(ajaxUri + "/audit/" + roomId, {
                        auditStatus: 2,
                        remark: text
                    }, function (apiResult) {
                        if (apiResult.resultCode === 2000) {
                            hot.tip.success("操作成功", function () {
                                window.location.reload();
                            });
                        } else {
                            hot.tip.error("操作失败--" + apiResult.resultMsg);
                        }
                    }, function () {
                    }, "post", 300);
                });
            }
        },
        sort: function (roomId, orderWeight) {
            layer.prompt({title: '排序，数字越大越排前', formType: 0, value: orderWeight + ""}, function (text, index) {
                hot.ajax(ajaxUri + "/sort/" + roomId, {
                    orderWeight: text,
                }, function (apiResult) {
                    if (apiResult.resultCode === 2000) {
                        hot.tip.success("操作成功", function () {
                            window.location.reload();
                        });
                    } else {
                        hot.tip.error("操作失败--" + apiResult.resultMsg);
                    }
                }, function () {
                }, "post", 300);
            });
        },
        modifyPlatformType: function (roomId, platform) {
            hot.ajax(ajaxUri + "/modifyPlatformType/" + roomId, {
                platform: platform,
            }, function (apiResult) {
                if (apiResult.resultCode === 2000) {
                    hot.tip.success("操作成功", function () {
                        window.location.reload();
                    });
                } else {
                    hot.tip.error("操作失败--" + apiResult.resultMsg);
                }
            }, function () {
            }, "post", 300);
        },
        rec: function (roomId) {
            hot.iframeModal("/live/edit/rec?roomId=" + roomId, "800px", "500px", '设置推荐信息');
        },
        enableRobot: function (roomId, enable) {
            hot.ajax(ajaxUri + "/enableRobot/" + roomId, {
                enable: enable
            }, function (apiResult) {
                if (apiResult.resultCode === 2000) {
                    hot.tip.success("操作成功", function () {
                        window.location.reload();
                    });
                } else {
                    hot.tip.error("操作失败--" + apiResult.resultMsg);
                }
            }, function () {
            }, "post", 300);
        },
        setRobotConfig: function (roomId) {
            robotConfigModal.show(function () {
                let form = $('#robot_form');
                $('[name=robot_room_id]', form).val(roomId);
                $('[name=robot_min]', form).val('1');
                $('[name=robot_max]', form).val('30');
                form.validateCallback(function () {
                    hot.ajax(ajaxUri + "/enableRobot/" + roomId, {
                        enable: true,
                        min: $('[name=robot_min]', form).val(),
                        max: $('[name=robot_max]', form).val()
                    }, function (apiResult) {
                        if (apiResult.resultCode === 2000) {
                            robotConfigModal.hide(function () {
                                hot.tip.success("操作成功", function () {
                                    window.location.reload();
                                });
                            });
                        } else {
                            hot.tip.error("操作失败--" + apiResult.resultMsg);
                        }
                    }, function () {
                    }, "post", 300);
                });
            });
        },
        modifyMemberNum: function (roomId) {
            layer.prompt({title: '修改直播间观看人数', formType: 0, value: ""}, function (text, index) {
                hot.ajax(ajaxUri + "/modifyMemberNum/" + roomId, {
                    num: text,
                }, function (apiResult) {
                    if (apiResult.resultCode === 2000) {
                        hot.tip.success("操作成功", function () {
                            window.location.reload();
                        });
                    } else {
                        hot.tip.error("操作失败--" + apiResult.resultMsg);
                    }
                }, function () {
                }, "post", 300);
            });
        },
        showReplyMessageModal: function (roomId) {
            hot.iframeModal(sendMessageUri + "?roomId=" + roomId, "800px", "380px", '发送直播间消息');
        },
        /**
         * 发送模板消息
         * @param roomId
         */
        sendTemplateMessage(roomId) {
            hot.confirm("是否确定需要发送开播通知?", function () {
                hot.ajax(sendTemplateMessage + ("/" + roomId), null, function (apiResult) {
                    if (apiResult.resultCode === 2000) {
                        hot.tip.success("操作成功");
                    } else {
                        hot.tip.error("操作失败--" + apiResult.resultMsg);
                    }
                }, function () {
                }, "post", 300);
            });

        },
        setRate(roomId, rate) {
            hot.iframeModal(ajaxUri + "/rate/edit?roomId=" + roomId, "650px", "400px", '设置抽成比例');
        }

    }
</script>
</body>
</html>
